/* -*- Mode:C; c-basic-offset:4 -*- */

search()
{
     if (sense(AHEAD, FOOD))
	  if (move)
	       (pickup) ? gohome() : search();
	  else
	       search();
     else 
     {
     state3:
	  if (flip(3))
	  { 
	       turn(LEFT); 
	       search(); 
	  }
	  else
	       if (flip(2))
	       { 
		    turn(RIGHT); 
		    search(); 
	       }
	       else 
		    (move) ? search() : goto state3;
     }
}

gohome()
{
     if (sense(AHEAD, HOME))
     {
	  move; // ignore failure!!! set state to 5555
	  drop;
	  search();
     }
     else
     {
     state11:
	  if (flip(3)) 
	  { 
	       turn(LEFT); 
	       gohome(); 
	  }
	  else
	       if (flip(2)) 
	       { 
		    turn(RIGHT); 
		    gohome();
	       }	
	       else
		    (move) ? gohome() : goto state11;
     }	     
}
